<template>
    <div>
        <el-row class="text-left">
            <div class="dlblock-mb20">
                <span class="pr5">单位名称</span>
                <el-input v-model.trim="orgName" size="medium" placeholder="请输入单位名称" style="width: 150px;"
                          :maxlength="20" show-word-limit clearable></el-input>
            </div>
            <!--<div class="dlblock-mb20">-->
            <!--<span class="pr5 ml10">部门名称</span>-->
            <!--<el-input v-model.trim="divisionName" size="medium" placeholder="请输入部门名称" style="width: 150px;" :maxlength="20" show-word-limit clearable></el-input>-->
            <!--</div>-->
            <div class="dlblock-mb20">
                <span class="pr5 ml10">线路</span>
                <el-input v-model.trim="circuit" size="medium" placeholder="请输入线路" style="width: 150px;" :maxlength="15"
                          show-word-limit clearable></el-input>
            </div>
            <div class="dlblock-mb20">
                <span class="pr5 ml10">人员姓名</span>
                <el-input v-model.trim="personName" size="medium" placeholder="请输入人员姓名" style="width: 150px;"
                          :maxlength="10" show-word-limit clearable></el-input>
            </div>
            <div class="dlblock-mb20">
                <span class="pr5 ml10">驾驶证号</span>
                <el-input v-model.trim="drivingNumber" size="medium" placeholder="请输入驾驶证号" style="width: 150px;"
                          :maxlength="12" show-word-limit clearable></el-input>
            </div>
            <div class="dlblock-mb20">
                <span class="pr5 ml10">人员工号</span>
                <el-input v-model.trim="personNumber" size="medium" placeholder="请输入人员工号" style="width: 150px;"
                          :maxlength="10" show-word-limit clearable></el-input>
            </div>
            <div class="dlblock-mb20">
                <span class="pr5 ml10">IC卡号</span>
                <el-input v-model.trim="ICNumber" size="medium" placeholder="请输入IC卡号" style="width: 150px;"
                          :maxlength="20" show-word-limit clearable></el-input>
            </div>
            <div class="dlblock-mb20 pr5 pl5">
                <el-button
                        @click="
						pages.page = 1;
						getDriverPageFn();
					"
                        class="el-icon-search ml5"
                        circle
                ></el-button>
            </div>
            <div class="dlblock-mb20 pr10 ml20">
                <el-button type="primary" @click="addBtn">添加</el-button>
            </div>
            <div class="dlblock-mb20 pr10">
                <el-button
                        @click="orgName=divisionName=circuit=circuit=personName=drivingNumber=personNumber=ICNumber='';getDriverPageFn();">
                    重置
                </el-button>
            </div>
            <div class="dlblock-mb20 pr10">
                <el-button type="danger" @click="delBtn">删除</el-button>
            </div>
            <div class="dlblock-mb20 pr10">
                <!--        <el-button @click="downloadBtn">-->
                <!--          导入驾驶员-->
                <!--        </el-button>-->
            </div>
            <div class="dlblock-mb20 pr10">
                <el-button @click="downloadBtn(1)">模版下载</el-button>
            </div>
            <div class="dlblock-mb20 pr10">
                <el-button @click="downloadBtn(2)">导出列表</el-button>
            </div>
            <div class="dlblock-mb20 pr10">
                <el-upload
                        class="upload-demo"
                        name="file"
                        ref="upload"
                        :action="config.baseURL + '/ba/org/driver/excelUpload'"
                        :on-preview="handlePreview"
                        :on-remove="handleRemove"
                        :auto-upload="false"
                >
                    <el-button slot="trigger" size="small" type="primary">模板导入</el-button>
                    <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">确定导入
                    </el-button>
                </el-upload>
            </div>
        </el-row>

        <el-table
                class="my-table"
                :data="tableData" stripe
                v-loading="loading"
                :header-row-class-name="'my-table-header'"
                @selection-change="handleSelectionChange"
                @row-dblclick="choseRow($event)"
                ref="myTable"
                border
        >
            <el-table-column type="selection" fixed width="55"></el-table-column>
            <el-table-column align="center" prop="driverId" v-if="false" label="人员ID"></el-table-column>
            <el-table-column align="center" prop="personInfoId" v-if="false" label="人员ID"></el-table-column>
            <el-table-column align="center" prop="personId" v-if="false" label="人员ID"></el-table-column>
            <el-table-column align="center" prop="orgId" v-if="false" label="分组id"></el-table-column>
            <el-table-column align="center" prop="personName" label="人员姓名"></el-table-column>
            <el-table-column align="center" prop="driverLicense" label="驾驶证号"></el-table-column>
            <el-table-column align="center" prop="orgName" label="单位名称"></el-table-column>
            <!--<el-table-column align="center" prop="deptName" label="部门名称"></el-table-column>-->
            <el-table-column align="center" prop="routeName" label="线路名称"></el-table-column>
            <el-table-column align="center" prop="icCard" label="IC卡号"></el-table-column>
            <el-table-column align="center" prop="driverStatus" label="人员状态"></el-table-column>
            <el-table-column align="center" prop="sex" label="性别"></el-table-column>
            <el-table-column align="center" prop="workCode" label="人员工号"></el-table-column>
            <el-table-column align="center" prop="beginTime" label="开始日期"></el-table-column>
            <el-table-column align="center" prop="getLicenseTime" label="领证时间"></el-table-column>
            <el-table-column align="center" prop="canDriveType" label="准驾车型"></el-table-column>
            <el-table-column align="center" width="100" prop="workCertificate" label="从业资格证"></el-table-column>
            <el-table-column align="center" width="150" prop="certificatePersonTime" label="从业人员资格有效期"></el-table-column>
            <el-table-column align="center" width="125" prop="certificateTime" label="资格证有效期"></el-table-column>
            <el-table-column align="center" width="125" prop="idCard" label="身份证号码"></el-table-column>
            <el-table-column align="center" width="125" prop="bankCardCode" label="银行卡信息"></el-table-column>
            <el-table-column align="center" width="145" prop="driLicArchivesOrg" label="驾驶证发证机关"></el-table-column>
            <el-table-column align="center" width="140" prop="driLicArchivesCode" label="驾驶证档案编号"></el-table-column>
            <el-table-column align="center" width="125" prop="driCode" label="准驾证号码"></el-table-column>
            <el-table-column align="center" width="125" prop="driEndDatetime" label="准驾有效期"></el-table-column>
            <el-table-column align="center" width="140" prop="phyExamDatetime" label="提交体检证明时间"></el-table-column>
            <el-table-column align="center" width="140" prop="sincerityExamDatetime" label="资格诚信考核时期"></el-table-column>
            <el-table-column align="center" prop="postalCode" label="邮政编码"></el-table-column>
            <el-table-column align="center" prop="email" label="电子邮件"></el-table-column>
            <el-table-column align="center" prop="workUnit" label="工作单位"></el-table-column>
            <el-table-column align="center" prop="address" label="通讯地址"></el-table-column>
            <el-table-column align="center" prop="officeTel" label="办公电话"></el-table-column>
            <el-table-column align="center" prop="mobileTel" label="移动电话"></el-table-column>
            <el-table-column align="center" prop="homeTel" label="家庭电话"></el-table-column>
            <el-table-column align="center" prop="birthday" label="出生日期"></el-table-column>
            <el-table-column align="center" prop="fixedCar" label="固定车辆"></el-table-column>
            <el-table-column align="center" prop="selfCode" label="自编号"></el-table-column>
            <el-table-column align="center" label="操作" fixed="right">
                <template slot-scope="{ row }">
                    <el-button  type="text" @click="editBtn(row)">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="my-pagination">
            <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :total="pages.total"
                    :page-size="pages.size"
                    :current-page="pages.page"
                    @current-change="pageChange"
            ></el-pagination>
        </div>

        <el-dialog title="驾驶员信息-添加" :visible.sync="addData.modal" width="700px" :close-on-click-modal="false"
                   v-dialogDrag>
            <el-form :model="addData" label-width="80px" ref="addForm">
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="姓名" prop="personName" :rules="required">
                            <el-input v-model="addData.personName" style="width: 200px" placeholder="请输入"
                                      :maxlength="10" show-word-limit clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11" :push="1">
                        <el-form-item label="单位" prop="orgId" :rules="required">
                            <el-cascader
                                    v-model="addData.orgId"
                                    :options="groupTree"
                                    :props="{ value: 'orgId', label: 'orgName', checkStrictly: true }"
                                    style="width: 200px;"
                                    :show-all-levels="false"
                                    @change="orgIdChange($event, 1)"
                                    filterable
                            ></el-cascader>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="性别" prop="sex" :rules="required">
                            <el-select v-model="addData.sex" style="width: 200px">
                                <el-option label="男" value="男"></el-option>
                                <el-option label="女" value="女"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11" :push="1">
                        <el-form-item label="部门">
                            <el-select v-model="addData.deptId" style="width: 200px" clearable>
                                <el-option v-for="(item, index) in deptIdList" :key="index" :label="item.deptName"
                                           :value="item.deptId"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="开始日期" prop="beginTime" :rules="required">
                            <el-date-picker style="width: 200px;" v-model="addData.beginTime" value-format="yyyy-MM-dd"
                                            type="date" placeholder="选择日期"></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11" :push="1">
                        <el-form-item label="线路">
                            <el-select v-model="addData.routeId" style="width: 200px" clearable>
                                <el-option v-for="(item, index) in routeIdList" :key="index" :label="item.routeName"
                                           :value="item.routeId"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="驾驶证号" prop="driverLicense" :rules="required">
                            <el-input v-model="addData.driverLicense" style="width: 200px" placeholder="请输入驾驶证号"
                                      :maxlength="12" show-word-limit clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11" :push="1">
                        <el-form-item label="IC卡号" prop="icCard" :rules="required">
                            <el-input v-model="addData.icCard" style="width: 200px" placeholder="请输入IC卡号"
                                      :maxlength="20" show-word-limit clearable></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="人员状态">
                            <el-select v-model="addData.driverStatus" style="width: 200px" clearable>
                                <el-option label="在职" value="在职"></el-option>
                                <el-option label="离职" value="离职"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11" :push="1">
                        <el-form-item label="人员工号" prop="workCode" :rules="required">
                            <el-input v-model="addData.workCode" style="width: 200px" placeholder="请输入人员工号"
                                      :maxlength="15" show-word-limit clearable></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>

            <div slot="footer" class="text-center">
                <el-button @click="addData.modal = false">取消</el-button>
                <el-button type="primary" @click="addSave">确认</el-button>
            </div>
        </el-dialog>

        <el-dialog title="驾驶员信息-编辑" :visible.sync="editData.modal" width="800px"  :close-on-click-modal="false"
                   v-dialogDrag @closed="getDriverPageFn">
            <el-tabs v-model="editData.active" @tab-click="showTab" type="card">
                <el-tab-pane label="基础信息" name="1">
                    <el-form :model="editData" label-width="80px" ref="editForm">
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="姓名" prop="personName" :rules="required">
                                    <el-input
                                            v-model="editData.personName"
                                            style="width: 200px"
                                            placeholder="请输入姓名"
                                            :maxlength="10"
                                            show-word-limit
                                            clearable
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="单位" prop="orgId" :rules="required">
                                    <el-cascader
                                            v-model="editData.orgId"
                                            :options="groupTree"
                                            :props="{ value: 'orgId', label: 'orgName', checkStrictly: true }"
                                            style="width: 200px;"
                                            :show-all-levels="false"
                                            @change="orgIdChange($event, 2)"
                                            filterable
                                    ></el-cascader>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="性别" prop="sex" :rules="required">
                                    <el-select v-model="editData.sex" style="width: 200px">
                                        <el-option label="男" value="男"></el-option>
                                        <el-option label="女" value="女"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="部门">
                                    <el-select v-model="editData.deptId" style="width: 200px" clearable>
                                        <el-option v-for="(item, index) in deptIdList" :key="index"
                                                   :label="item.deptName" :value="item.deptId"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="开始日期" prop="beginTime" :rules="required">
                                    <el-date-picker
                                            style="width: 200px;"
                                            v-model="editData.beginTime"
                                            value-format="yyyy-MM-dd"
                                            type="date"
                                            placeholder="选择日期"
                                    ></el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="线路">
                                    <el-select v-model="editData.routeId" style="width: 200px" clearable>
                                        <el-option v-for="(item, index) in routeIdList" :key="index"
                                                   :label="item.routeName" :value="item.routeId"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="驾驶证号" prop="orgId" :rules="required">
                                    <el-input
                                            v-model="editData.driverLicense"
                                            style="width: 200px"
                                            placeholder="请输入驾驶证号"
                                            :maxlength="12"
                                            show-word-limit
                                            clearable
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="IC卡号" prop="orgId" :rules="required">
                                    <el-input v-model="editData.icCard" style="width: 200px" placeholder="请输入IC卡号"
                                              :maxlength="20" show-word-limit clearable></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="人员状态">
                                    <el-select v-model="editData.driverStatus" style="width: 200px" clearable>
                                        <el-option label="在职" value="在职"></el-option>
                                        <el-option label="离职" value="离职"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="人员工号">{{ editData.workCode }}</el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-tab-pane>

                <el-tab-pane label="详细信息" name="2">
                    <el-form label-width="145px">
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="领证日期">
                                    <el-date-picker
                                            style="width: 200px;"
                                            v-model="editData.getLicenseTime"
                                            value-format="yyyy-MM-dd"
                                            type="date"
                                            placeholder="选择日期"
                                    ></el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="身份证号">
                                    <el-input
                                            v-model="editData.idCard"
                                            style="width: 200px"
                                            placeholder="请输入身份证号"
                                            :maxlength="18"
                                            show-word-limit
                                            clearable
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="准驾车型">
                                    <el-select v-model="editData.canDriveType" style="width: 200px" clearable>
                                        <el-option v-for="(item, index) in canDriveTypeList" :key="index"
                                                   :label="item.codeName" :value="item.codeValue"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="从业资格证">
                                    <el-input
                                            v-model="editData.workCertificate"
                                            style="width: 200px"
                                            placeholder="请输入从业资格证"
                                            :maxlength="20"
                                            show-word-limit
                                            clearable
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="从业人员资格有效期">
                                    <el-date-picker
                                            style="width: 200px;"
                                            v-model="editData.certificatePersonTime"
                                            value-format="yyyy-MM-dd"
                                            type="date"
                                            placeholder="选择日期"
                                    ></el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="资格证有效期">
                                    <el-date-picker
                                            style="width: 200px;"
                                            v-model="editData.certificateTime"
                                            value-format="yyyy-MM-dd"
                                            type="date"
                                            placeholder="选择日期"
                                    ></el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="驾驶证档案编号">
                                    <el-input
                                            v-model="editData.driLicArchivesCode"
                                            style="width: 200px"
                                            placeholder="请输入驾驶证档案编号"
                                            :maxlength="20"
                                            show-word-limit
                                            clearable
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="准驾证号码">
                                    <el-input
                                            v-model="editData.driCode"
                                            style="width: 200px"
                                            placeholder="请输入准驾证号码"
                                            :maxlength="20"
                                            show-word-limit
                                            clearable
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="驾照有效期">
                                    <el-date-picker
                                            style="width: 200px;"
                                            v-model="editData.driEndDatetime"
                                            value-format="yyyy-MM-dd"
                                            type="date"
                                            placeholder="选择日期"
                                    ></el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="提交体检证明时间">
                                    <el-date-picker
                                            style="width: 200px;"
                                            v-model="editData.phyExamDatetime"
                                            value-format="yyyy-MM-dd"
                                            type="date"
                                            placeholder="选择日期"
                                    ></el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="资格诚信考核日期">
                                    <el-date-picker
                                            style="width: 200px;"
                                            v-model="editData.sincerityExamDatetime"
                                            value-format="yyyy-MM-dd"
                                            type="date"
                                            placeholder="选择日期"
                                    ></el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="银行卡信息">
                                    <el-input
                                            v-model="editData.bankCardCode"
                                            style="width: 200px"
                                            placeholder="请输入银行卡信息"
                                            :maxlength="25"
                                            show-word-limit
                                            clearable
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="驾驶证发证机关">
                                    <el-input
                                            v-model="editData.driLicArchivesOrg"
                                            style="width: 200px"
                                            placeholder="请输入驾驶证发证机关"
                                            :maxlength="30"
                                            show-word-limit
                                            clearable
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-tab-pane>

                <el-tab-pane label="联系方式" name="3">
                    <el-form label-width="80px">
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="出生日期">
                                    <el-date-picker style="width: 200px;" v-model="editData.birthday"
                                                    value-format="yyyy-MM-dd" type="date"
                                                    placeholder="选择日期"></el-date-picker>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="移动电话">
                                    <el-input v-model="editData.mobileTel" style="width: 200px" placeholder="请输入移动电话"
                                              :maxlength="11" show-word-limit clearable></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="家庭电话">
                                    <el-input v-model="editData.homeTel" style="width: 200px" placeholder="请输入家庭电话"
                                              :maxlength="11" show-word-limit clearable/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="办公电话">
                                    <el-input v-model="editData.officeTel" style="width: 200px" placeholder="请输入办公电话"
                                              :maxlength="11" show-word-limit clearable/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="邮政编码">
                                    <el-input v-model="editData.postalCode" style="width: 200px" placeholder="请输入邮政编码"
                                              :maxlength="6" show-word-limit clearable/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="电子邮件">
                                    <el-input v-model="editData.email" style="width: 200px" placeholder="请输入电子邮件"
                                              :maxlength="20" show-word-limit clearable/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-form-item label="工作单位">
                                <el-input v-model="editData.workUnit" style="width: 580px;" placeholder="请输入工作单位"
                                          :maxlength="20" show-word-limit clearable/>
                            </el-form-item>
                        </el-row>
                        <el-row>
                            <el-form-item label="通讯地址">
                                <el-input v-model="editData.address" style="width: 580px;" placeholder="请输入通讯地址"
                                          :maxlength="25" show-word-limit clearable/>
                            </el-form-item>
                        </el-row>
                    </el-form>
                </el-tab-pane>
                <!--<el-tab-pane label="照片信息" name="4">
                    <el-form label-width="100px">
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="照片">
                                    <single-img v-model="editData.imgInfo"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="身份证图片">
                                    <single-img v-model="editData.IdPhoto"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="驾驶证图片">
                                    <single-img v-model="editData.DrivingLicense"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-tab-pane>

                <el-tab-pane label="其他信息" name="5">
                    <el-form label-width="100px">
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="固定车辆">
                                    <el-input v-model="editData.fixedCar" placeholder="请输入固定车辆" :maxlength="30"
                                              show-word-limit clearable/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11" :push="1">
                                <el-form-item label="自编号">
                                    <el-input v-model="editData.selfCode" placeholder="请输入自编号" :maxlength="30"
                                              show-word-limit clearable/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-tab-pane>-->
            </el-tabs>

            <div slot="footer" class="text-center">
                <el-button @click="editData.modal = false">取消</el-button>
                <el-button type="primary" @click="editSave">确认</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    var rows = null;
    import {
        getDriverPage,
        delDriver,
        addDriver,
        setDriver,
        getGroupTree,
        getDepartmentByGroupId,
        getLineByGroupId,
        getPlatformCodeByCondition
    } from '@/api';
    import {downloadToTagByA} from '@/utils/config';
    import config from '@/utils/config';

    export default {
        name: 'PersonDriver',
        //  components: {SingleImg},
        data() {
            return {
                config,
                required: {
                    required: true,
                    message: '此输入框必填',
                    trigger: 'blur',
                    file: this.file
                },
                unitName: '',
                divisionName: '',
                orgName: '',
                circuit: '',
                personName: '',
                drivingNumber: '',
                personNumber: '',
                ICNumber: '',
                workUnit: '',
                tableData: [],
                loading: false,
                pages: {
                    page: 1,
                    total: 0
                },
                tableSelection: [],
                addData: {
                    modal: false,
                    personName: '',
                    sex: '',
                    beginTime: '',
                    orgName: '',
                    orgId: [],
                    deptId: '',
                    routeId: '',
                    driverLicense: '',
                    icCard: '',
                    driverStatus: '',
                    workUnit: '',
                    workCode: ''
                },
                editData: {
                    modal: false,
                    active: '1',
                    driverId: '',
                    personName: '',
                    sex: '',
                    beginTime: '',
                    orgId: [],
                    deptId: '',
                    routeId: '',
                    driverLicense: '',
                    icCard: '',
                    driverStatus: '',
                    getLicenseTime: '',
                    canDriveType: '',
                    certificatePersonTime: '',
                    driLicArchivesCode: '',
                    driEndDatetime: '',
                    sincerityExamDatetime: '',
                    driLicArchivesOrg: '',
                    idCard: '',
                    workCertificate: '',
                    certificateTime: '',
                    driCode: '',
                    phyExamDatetime: '',
                    bankCardCode: '',
                    birthday: '',
                    mobileTel: '',
                    homeTel: '',
                    officeTel: '',
                    postalCode: '',
                    email: '',
                    workUnit: '',
                    address: '',
                    imgInfo: '',
                    fixedCar: '',
                    selfCode: '',
                    DrivingLicense: '',
                    IdPhoto: '',
                    workCode: ''
                },
                // 分组树
                groupTree: [],
                // 部门集合
                deptIdList: [],
                // 线路集合
                routeIdList: [],
                // 准驾车型集合
                canDriveTypeList: []
            };
        },
        created() {
            // this.getDriverPageFn();
            // this.getGroupTreeFn();
            // this.getPlatformCodeByConditionFn('DRIVERTYPE', 'canDriveTypeList');
        },
        destroyed: function () {
        },
        methods: {
            showTab() {//选项卡点击事件
                if (this.editData.active == 2) {//详细信息
                    if (null != rows) {
                        this.editData.workCertificate = rows.workCertificate;
                        this.editData.certificatePersonTime = rows.certificatePersonTime;
                        this.editData.certificateTime = rows.certificateTime

                        this.editData.driLicArchivesCode = rows.driLicArchivesCode
                        this.editData.driCode = rows.driCode
                        this.editData.driEndDatetime = rows.driEndDatetime
                        this.editData.phyExamDatetime = rows.phyExamDatetime

                        this.editData.sincerityExamDatetime = rows.sincerityExamDatetime
                        this.editData.bankCardCode = rows.bankCardCode
                        this.editData.driLicArchivesOrg = rows.driLicArchivesOrg
                    }
                } else if (this.editData.active == 3) {//
                    if (null != rows) {
                        this.editData.birthday = rows.birthday
                        this.editData.mobileTel = rows.mobileTel
                        this.editData.homeTel = rows.homeTel
                        this.editData.officeTel = rows.officeTel
                        this.editData.postalCode = rows.postalCode
                        this.editData.email = rows.email
                        this.editData.workUnit = rows.workUnit
                        this.editData.address = rows.address
                    }

                }
            },
            choseRow(row) {//双击row函数
                if (row) {
                    this.$refs.myTable.toggleRowSelection(row);
                }
            },
            keepPageNum() {
                sessionStorage.setItem('PersonDriver', this.pages.page);
            },
            getPageNum() {
                var page = sessionStorage.getItem('PersonDriver');
                if (null != page) {
                    this.pages.page = page;
                    sessionStorage.removeItem('PersonDriver');
                }
            },
            submitUpload() {
                this.$refs.upload.submit();
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePreview(file) {
                console.log(file);
            },
            addSave() {
                this.$refs['addForm'].validate(valid => {
                    if (valid) {
                        addDriver({
                            personName: this.addData.personName,
                            sex: this.addData.sex,
                            beginTime: this.addData.beginTime,
                            orgId: this.addData.orgId[this.addData.orgId.length - 1],
                            departId: this.addData.deptId,
                            routeId: this.addData.routeId,
                            driverLicense: this.addData.driverLicense,
                            icCard: this.addData.icCard,
                            driverStatus: this.addData.driverStatus,
                            workCode: this.addData.workCode
                        }).then(res => {
                            this.$message.success(res.data);
                            this.addData.modal = false;
                            this.getDriverPageFn();
                        });
                    } else {
                        return false;
                    }
                });
            },
            orgIdChange(orgId, t) {
                if (t == 1) {
                    // 添加
                    if (orgId.length && null != orgId && '' != orgId) {
                        getDepartmentByGroupId(orgId[orgId.length - 1]).then(res => {
                            this.deptIdList = res.data;
                        });
                        //获取线路
                        getLineByGroupId(orgId[orgId.length - 1]).then(res => {
                            this.routeIdList = res.data;
                        });
                    } else {
                        this.deptIdList = [];
                        this.routeIdList = [];
                    }
                    this.addData.deptId = '';
                    this.addData.routeId = '';
                } else {

                    // 编辑
                    if (orgId.length && null != orgId && orgId != '') {
                        getDepartmentByGroupId(orgId[orgId.length - 1]).then(res => {
                            this.deptIdList = res.data;
                        });
                        getLineByGroupId(orgId[orgId.length - 1]).then(res => {
                            this.routeIdList = res.data;
                        });
                    } else {
                        this.deptIdList = [];
                        this.routeIdList = [];
                    }
                    this.addData.deptId = '';
                    this.addData.routeId = '';
                }
            },
            addBtn() {
                this.addData = {
                    modal: true,
                    personName: '',
                    sex: '',
                    beginTime: '',
                    orgId: [],
                    deptId: '',
                    routeId: '',
                    driverLicense: '',
                    icCard: '',
                    driverStatus: '',
                    workCode: ''
                };
                this.deptIdList = [];
                this.routeIdList = [];
            },
            downloadBtn(t) {
                downloadToTagByA(t == 1 ? '/ba/org/driver/exportmoudle' : '/ba/org/driver/export', {
                   token:sessionStorage.token,
                    orgName: this.orgName,
                    deptName: this.divisionName,
                    routeName: this.circuit,
                    personName: this.personName,
                    driverLicense: this.drivingNumber,
                    workCode: this.personNumber,
                    icCard: this.ICNumber
                });
            },
            editSave() {
                this.$refs['editForm'].validate(valid => {
                    if (valid) {
                        setDriver({
                            driverId: this.editData.driverId,
                            personName: this.editData.personName,
                            sex: this.editData.sex,
                            beginTime: this.editData.beginTime,
                            orgId: this.editData.orgId[this.editData.orgId.length - 1],
                            departId: this.editData.deptId,
                            routeId: this.editData.routeId,
                            driverLicense: this.editData.driverLicense,
                            icCard: this.editData.icCard,
                            driverStatus: this.editData.driverStatus,
                            getLicenseTime: this.editData.getLicenseTime,
                            canDriveType: this.editData.canDriverType,
                            certificatePersonTime: this.editData.certificatePersonTime,
                            driLicArchivesCode: this.editData.driLicArchivesCode,
                            driEndDatetime: this.editData.driEndDatetime,
                            sincerityExamDatetime: this.editData.sincerityExamDatetime,
                            driLicArchivesOrg: this.editData.driLicArchivesOrg,
                            idCard: this.editData.idCard,
                            workCertificate: this.editData.workCertificate,
                            certificateTime: this.editData.certificateTime,
                            driCode: this.editData.driCode,
                            phyExamDatetime: this.editData.phyExamDatetime,
                            bankCardCode: this.editData.bankCardCode,
                            birthday: this.editData.birthday,
                            mobileTel: this.editData.mobileTel,
                            homeTel: this.editData.homeTel,
                            officeTel: this.editData.officeTel,
                            postalCode: this.editData.postalCode,
                            email: this.editData.email,
                            workUnit: this.editData.workUnit,
                            address: this.editData.address,
                            imgInfo: this.editData.imgInfo,
                            fixedCar: this.editData.fixedCar,
                            selfCode: this.editData.selfCode,
                            DrivingLicense: this.editData.DrivingLicense,
                            IdPhoto: this.editData.IdPhoto,
                            workCode: this.editData.workCode,
                            personId: rows == null ? null : rows.personId
                        }).then(res => {
                            this.$message.success(res.data);
                        });
                    } else {
                        this.$message.warning('请输入必填项!');
                        return false;
                    }
                });
            },
            getDriverPageFn() {
                rows=null;
                this.loading = true;
                getDriverPage({
                    pageNum: this.pages.page,
                    orgName: this.orgName,
                    deptName: this.divisionName,
                    routeName: this.circuit,
                    personName: this.personName,
                    driverLicense: this.drivingNumber,
                    workCode: this.personNumber,
                    icCard: this.ICNumber
                })
                    .then(res => {
                        this.tableData = res.data.list;
                        this.pages.total = res.data.count;
                    })
                    .finally(() => {
                        this.loading = false;
                    });
            },
            rowDblclick(row) {
                this.editBtn(row);
            },
            editBtn(row) {

                this.editData = {
                    modal: true,
                    active: '1',
                    driverId: row.driverId,
                    personName: row.personName,
                    sex: row.sex,
                    beginTime: row.beginTime,
                    orgId: [row.orgId],
                    deptId: row.deptId,
                    routeId: row.routeId,
                    driverLicense: row.driverLicense,
                    icCard: row.icCard,
                    driverStatus: row.driverStatus,
                    getLicenseTime: row.getLicenseTime,
                    canDriveType: row.canDriverType,
                    certificatePersonTime: row.certificatePersonTime,
                    driLicArchivesCode: row.driLicArchivesCode,
                    driEndDatetime: row.driEndDatetime,
                    sincerityExamDatetime: row.sincerityExamDatetime,
                    driLicArchivesOrg: row.driLicArchivesOrg,
                    idCard: row.idCard,
                    workCertificate: row.workCertificate,
                    certificateTime: row.certificateTime,
                    driCode: row.driCode,
                    phyExamDatetime: row.phyExamDatetime,
                    bankCardCode: row.bankCardCode,
                    birthday: row.birthday,
                    mobileTel: row.mobileTel,
                    homeTel: row.homeTel,
                    officeTel: row.officeTel,
                    postalCode: row.postalCode,
                    email: row.email,
                    workUnit: row.workUnit,
                    address: row.address,
                    imgInfo: row.imgInfo,
                    fixedCar: row.fixedCar,
                    selfCode: row.selfCode,
                    DrivingLicense: row.DrivingLicense,
                    IdPhoto: row.IdPhoto,
                    workCode: row.workCode
                };
                rows = row;
                this.orgIdChange([row.orgId], 2);
            },
            delBtn() {
                if (this.tableSelection.length) {
                    this.$confirm('确认删除这些记录吗?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    })
                        .then(() => {
                            delDriver({driverIds: this.tableSelection.map(item => item.driverId)}).then(res => {
                                this.$message.success(res.data);
                                this.getDriverPageFn();
                            });
                        })
                        .catch(() => {
                        });
                }
            },
            handleSelectionChange(val) {
                this.tableSelection = val;
            },
            pageChange(val) {
                this.pages.page = val;
                this.getDriverPageFn();
            },
            getGroupTreeFn() {
                getGroupTree().then(res => {
                    this.groupTree = res.data.children;
                });
            },
            getPlatformCodeByConditionFn(codeClassType, name) {
                getPlatformCodeByCondition({codeClassType}).then(res => {
                    this[name] = res.data;
                });
            }
        }
    };
</script>

<style scoped></style>
